/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var xmlHttpAkunSetting= createXMLHttpObject();

var AjaxPath= "application/core/ajax/";

function getOffset( el ) {
    var _x = 0;
    var _y = 0;
    while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
        _x += el.offsetLeft - el.scrollLeft;
        _y += el.offsetTop - el.scrollTop;
        el = el.parentNode;
    }
    return {
        top: _y, 
        left: _x
    };
}


function AjaxAkunSettingForm(pTargetFile, pTargetId){
    var ServerPage= AjaxPath + pTargetFile;
    var mPosisi= 1;	

    xmlHttpAkunSetting= createXMLHttpObject();
    processData(xmlHttpAkunSetting, ServerPage, "", pTargetId, mPosisi); 
}

$(document).ready(function() {
    $("#Akun-Menu ul li").click(function(){
        isSelected= $(this).attr("class");
        id= $(this).attr("id");
        if(isSelected != "Selected") {
            $("#Akun-Menu ul li.Selected").removeClass("Selected");
            $(this).addClass("Selected");

            //SETUP: Posisi Navigator Pointer
            var tTargetPos= $(this).attr("rel");
            $("#AkunMenu-Navigator").animate({
                marginLeft: tTargetPos
            }, 300);
        }
    });
    
    var AkunSettingSubmitValidation=false;
    // A K U N   S E T T I N G
    $("#AkunSetting-Container li").click(function(){
        id= $(this).attr("rel");
        //$(this).bind("mousehover");
        $("#AkunSetting-Form").dialog("open");
        
        if(id=="Username") {
            path= "ajax.akun.FormUsername.php";
            AkunSettingSubmitValidation= "username";
        }
        else if(id=="Password") {
            path= "ajax.akun.FormPassword.php";
            AkunSettingSubmitValidation= "password";
        }
        else {
            path= "ajax.akun.FormEmail.php";
            AkunSettingSubmitValidation= "email";
        }
            
        AjaxAkunSettingForm(path, "AkunSetting-Form");
        
    });
    
    $("#AkunSetting-Container li").hover(		
        //Mouseover, fadeIn the hidden hover class	
        function() {
            $(this).stop(true, true).css('background', '#eee');
        }, 
	
        //Mouseout, fadeOut the hover class
        function() {
            $(this).stop(true, true).css('background', '#fff');	
        });
    
    
    $("#AkunSetting-Form").dialog({
        autoOpen:false,
        resizable: false,
        width:800,
        modal: true,
        position: "top",
        buttons: {
            "Simpan": function() {
                Err= true;
                if(AkunSettingSubmitValidation == "username")
                    Err= ValSubmitAkunSettingUsername();
                else if(AkunSettingSubmitValidation == "password")
                    Err= ValSubmitAkunSettingPassword();
                else if(AkunSettingSubmitValidation == "email")
                    Err= ValSubmitAkunSettingEmail();
                
                if(!Err) {
                    $( this ).dialog( "close" );
                    document.formAkunSetting.submit();
                }
            },
            "Batal": function() {
                $( this ).dialog( "close" );
            }
        }
    });
    ////
    
    // S E T T I N G  O T O R I T A S   
    /* AUTOCOMPLETE: LIST MAHASISWA */
    $( "#fPerson.Autocomplete" ).click(function(){ 
        //SETTER KURIKULUM & EDIT MATKUL
        mKat= document.getElementById("fKategori").value;
        
        //SET Combogrid value addition
        $( "#fPerson" ).combogrid( "option", "url", AjaxPath + 'ajax.AutocompletePerson.php?id='+mKat+'&edit_matakuliah_id='+mKat );

        //SETTING: Width Autocomplete
        tWidth= $( "#fPerson" ).css("width");
        $( ".combogrid" ).css("width", tWidth);
        
        //SETTING: Autocomplete ALT
        temp= tWidth.split("px");
        tWidth= temp[0]-100;
        $(".Autocomplete-Alt").css("width", tWidth+"px");
        $(".Autocomplete-Alt").css("margin-left", 100+"px");
    });
        
        
    $( "#fPerson.Autocomplete" ).combogrid({
        url: AjaxPath + 'ajax.AutocompletePerson.php',
        debug:true,
        //replaceNull: true,
        colModel: [{
            'columnName':'fNomorInduk',
            'width':'25',
            'label':'NOMOR INDUK'
        }, {
            'columnName':'fNama',
            'width':'45',
            'label':'NAMA'
        },{
            'columnName':'fKategori',
            'width':'30',
            'label':'KATEGORI'
        }],
        select: function( event, ui ) {
            tVal= ui.item.fNomorInduk;
            tValAlt= ui.item.fNama;
            
            tPersonId= ui.item.fPersonId;

            $( "#fPerson" ).val( tVal );
            $(".Autocomplete-Alt").html(tValAlt);
            
            $( "#fPersonId" ).val(tPersonId);
            $( "#fUsername" ).val(tVal);
            return false;
        }
    });
    
    
});
